package network.course3;

public class Addition implements  Runnable{
    private int count;

    public Addition(int count) {
        this.count = count;
    }

    @Override
    public synchronized void run() {
        try {
             while (count>0){
                 System.out.println(Thread.currentThread().getName()+count);
                 count--;
             }

            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        Addition addition=new Addition(20);
        Thread thread=new Thread(addition);
        Thread thread2=new Thread(addition);
        Thread thread3=new Thread(addition);
        thread.setName("线程一");
        thread2.setName("线程二");
        thread3.setName("线程三");
        thread.start();
        thread2.start();
        thread3.start();
    }
}
